package com.appkubes.mall.admin.application.utm.utm.dao;

import com.appkubes.mall.admin.application.utm.utm.entity.dto.UtmStatisDTO;
import com.appkubes.mall.core.pojo.MallUtmSourceMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface UtmSourceDao extends MallUtmSourceMapper {

    @Select({
            "<script>",
            "SELECT user.name, user.tel, user.gender, user.create_time,user.update_time," +
            " utm.utm_name,user_utm.register_ip,user_utm.platform_type FROM mall_user_utm as user_utm" +
            " LEFT JOIN mall_user as user ON user_utm.user_key=user.user_key" +
            " LEFT JOIN mall_utm_source as utm ON user_utm.utm_source=utm.utm_key" +
            " WHERE user_utm.flex_segment1=#{sourceType}"+
            " <when test='utmName!=null'>" +
            " AND utm.utm_name like '%${utmName}%'" +
            " </when>",
            "</script>"
    })
    List<UtmStatisDTO> getList(@Param("utmName")String utmName, @Param("sourceType")String sourceType);

    @Select({
            "<script>",
            "SELECT user.name, user.tel, user.gender, user.create_time,user.update_time," +
                    " utm.utm_name,user_utm.register_ip,user_utm.platform_type FROM mall_user_utm as user_utm" +
                    " LEFT JOIN mall_user as user ON user_utm.user_key=user.user_key" +
                    " LEFT JOIN mall_utm_source as utm ON user_utm.utm_source=utm.utm_key" +
                    " WHERE user_utm.flex_segment1=#{sourceType}"+
                    " AND user.create_time BETWEEN ${startTime} AND ${endTime}" +
                    " <when test='utmName!=null'>" +
                    " AND utm.utm_name like '%${utmName}%'" +
                    " </when>",
            "</script>"
    })
    List<UtmStatisDTO> getList(@Param("utmName")String utmName, @Param("sourceType")String sourceType
            , @Param("startTime")Integer startTime, @Param("endTime")Integer endTime);
}
